package object

import (
	"time"

	v1 "code.byted.org/bytertc/whiteboard_server/biz/api/pb/v1"
	"google.golang.org/protobuf/proto"
)

const InitialActionCount = 1

type Object interface {
	GetAppId() string
	GetRoomId() string
	GetBoardId() int32
	GetActionCount() int32
	AddActionCount(int32)
	GetInitStatus() bool
	SetInitStatus(finished bool)
	Set(another ProtoObject)
	proto.Message
}

// Element 白板上可绘制的元素
type Element interface {
	Object
	GetPageId() string
	GetObjId() string
	ToProto() *v1.Element
	SetStyle(style Style)
	SetRange(r Range)
	AppendPoints(points PenPoints)
	SetActionId(id int32)
	GetActionId() int32
}

type Style interface {
	GetStyle() *v1.Style
}

type Range interface {
	GetStart() *v1.Point
	GetEnd() *v1.Point
}

type PenPoints interface {
	GetPoints() []*v1.PenPoint
}

type ProtoObject interface {
	proto.Message
}

// Board 白板本身
type Board interface {
	Object
	GetUpdateAt() time.Time
	//CreatePage(newPages []*v1.PageInfo)
	//TurnPage(currentPageId int32) bool
	//ScalePage(scale float64)
}

type Info struct {
	AppId  string
	RoomId string
	*v1.Element
}

func (i *Info) GetAppId() string {
	return i.AppId
}

func (i *Info) GetRoomId() string {
	return i.RoomId
}

func (i *Info) AddActionCount(newPhases int32) {
	i.ActionCount += newPhases
}

func (i *Info) SetTimestamp(t uint64) {
	i.Timestamp = t
}

func (i *Info) SetActionId(id int32) {
	i.ActionId = id
}

func (i *Info) GetInitStatus() bool {
	return i.Initialized
}
func (i *Info) SetInitStatus(finished bool) {
	i.Initialized = finished
}

func (i *Info) toProto(obj proto.Message) *v1.Element {
	data, _ := proto.Marshal(obj)
	ele, _ := proto.Clone(i.Element).(*v1.Element)
	ele.Data = data
	return ele
}
